package com.demo.test.juc.lock;

/**
 * @author gy
 * @date 2023/7/28
 */
public class DeadLock {
    public static void main(String[] args) {
        Object o1 = new Object();
        Object o2 = new Object();
        new Thread(() ->{
            synchronized (o1){
                System.out.println("o1 进来了");
                try {
                    Thread.sleep(3000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                synchronized (o2){
                    System.out.println("o2 获得了");
                }
            }
        },"A").start();
        new Thread(() ->{
            synchronized (o2){
                System.out.println("o2 进来了");
                synchronized (o1){
                    System.out.println("o1 获得了");
                }
            }
        },"B").start();
    }
}
